<?php
/**
 * 短信记录模型
 * @date    2020-01-01
 * @author  kiro
 * @email   294843009@qq.com
 * @version 1.0
 */
/*

	/*
	 * All rights Reserved, Designed By www.youyacao.com <br>
	 * @Description:短信 <br>
	 * @version 蜻蜓C影视追剧系统  <br>
	 * @author:成都市一颗优雅草科技有限公司  <br>
	 * 注意：使用我司开源源代码请遵循license文件的协议仅供个人非盈利使用，禁止用于其他的商业用途
	 * 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
	 * 正版系统查询系统 zhengbancha.youyacao.com
	 */

namespace App\Models;

class SmsLog extends BaseModel
{
    protected $table = 'sms_log';

    protected $fillable = [
        'phone',
        'ip',
        'day',
        'status'
    ];

    //判断短信次数
    public static function can($phone, $t = 3)
    {
        //$num = self::where('phone', $phone)->whereBetween('created_at', [strtotime("-1 hour"), time()])->count();
        $num = self::where('phone', $phone)->where('day', date('Ymd'))->count();
        if ($num >= $t) {
            return false;
        }
        self::create([
            'phone' => $phone,
            'day'   => date('Ymd'),
            'ip'    => request()->ip()
        ]);
        return true;
    }
}
